package com.jason.campusinn.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.MeasureSpec;

public class BezierCurveView2 extends View{
	
	private static final String TAG = "com.example.propertyanimsecdemo.BezierCurveView";
		
	private Paint paint;
	
	private Path path;
	
	private int start_point_x;
	private int start_point_y;
	private int center_obj_x;
	private int center_obj_y;

	private int view_with;
	private int view_height;
	
	private DensityUtil density;
	
	private final int DUMMY_OBJ_CENTER_X = 100/2;//需要根据图片的大小进行调整
	private final int DUMMY_OBJ_CENTER_y = 25/2;//需要根据图片的大小进行调整
	
	private final int DUMMY_AERA = 100;
	
	private int SCALE = 6;
	private int CENTER_X =this.getMeasuredWidth()/2;
	private int CENTER_Y =this.getMeasuredHeight()/2;
//	private int CENTER_X =60;
//	private int CENTER_Y =120;
	
	public BezierCurveView2(Context context, AttributeSet attrs){
		super(context,attrs);
		init(context);
	}
	
	public BezierCurveView2(Context context){
		super(context);
		init(context);
	}
	
	private void init(Context context){	
		
		density = new DensityUtil(context);
		
		SCALE = (int) (3*density.getScale());
		if ("HUAWEI P8max".equals(Build.MODEL)) {
			CENTER_X = (int) (50 * density.getScale());
			CENTER_Y = (int) (80 * density.getScale());
		} else {
			CENTER_X = (int) (30 * density.getScale());
			CENTER_Y = (int) (80 * density.getScale());
		}

		paint = new Paint();
		paint.setColor(Color.parseColor("#606264"));
		paint.setAntiAlias(true);
		paint.setStyle(Style.STROKE);
		paint.setStrokeWidth(1);

		path = new Path();

		center_obj_x = DUMMY_OBJ_CENTER_X;
		center_obj_y = DUMMY_OBJ_CENTER_y;

		start_point_x = center_obj_x;
		start_point_y = center_obj_y;

		view_with = density.dip2px(DUMMY_AERA);
		view_height = density.dip2px(DUMMY_AERA);
	}

	public void setObjCenter(int x, int y)
	{
		center_obj_x = x;
		center_obj_y = y;
	}

	public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//		CENTER_X = (int) ((MeasureSpec.getSize(widthMeasureSpec)/2));
//		CENTER_Y = (int) ((MeasureSpec.getSize(heightMeasureSpec)/2));

	}

	public void onDraw(Canvas canvas){
		canvas.drawColor(Color.TRANSPARENT);
		path.reset();
//		path.moveTo(start_point_x, start_point_y);
//		path.cubicTo(getMeasuredWidth()+center_obj_x, start_point_y+center_obj_y,
//				start_point_x+center_obj_x, getMeasuredHeight()+center_obj_y,
//				getMeasuredWidth()+center_obj_x, getMeasuredHeight()+center_obj_y);

//		path.cubicTo(view_with, start_point_y,
//		start_point_x, view_height,
//		view_with+start_point_x, view_height+start_point_y);

		//1
//		path.moveTo(14.63f*SCALE+CENTER_X, 21.33f*SCALE+CENTER_Y);
//		path.cubicTo(-4.88f*SCALE+CENTER_X, 16.46f*SCALE+CENTER_Y,
//				-4.88f*SCALE+CENTER_X, 8.54f*SCALE+CENTER_Y,
//				14.64f*SCALE+CENTER_X, 3.66f*SCALE+CENTER_Y);
//
//		path.moveTo(14.64f*SCALE+CENTER_X, 3.66f*SCALE+CENTER_Y);
//		path.lineTo(14.8f*SCALE+CENTER_X, 3.62f*SCALE+CENTER_Y);
//
//		path.moveTo(14.8f*SCALE+CENTER_X, 3.62f*SCALE+CENTER_Y);
//		path.cubicTo(16.22f*SCALE+CENTER_X, 3.27f*SCALE+CENTER_Y,
//				17.69f*SCALE+CENTER_X, 2.95f*SCALE+CENTER_Y,
//				19.22f*SCALE+CENTER_X, 2.65f*SCALE+CENTER_Y);

		//2
		path.moveTo(19.22f*SCALE+CENTER_X, 2.65f*SCALE+CENTER_Y);
		path.cubicTo(22f*SCALE+CENTER_X, 2.1f*SCALE+CENTER_Y,
				22f*SCALE+CENTER_X, 2.1f*SCALE+CENTER_Y,
				28.05f*SCALE+CENTER_X, 1.27f*SCALE+CENTER_Y);

		path.moveTo(28.05f*SCALE+CENTER_X, 1.27f*SCALE+CENTER_Y);
		path.cubicTo(42.48f*SCALE+CENTER_X, -0.5f*SCALE+CENTER_Y,
				59.6f*SCALE+CENTER_X, -0.42f*SCALE+CENTER_Y,
				73.79f*SCALE+CENTER_X, 1.5f*SCALE+CENTER_Y);

		//3
//		path.moveTo(73.79f*SCALE+CENTER_X, 1.5f*SCALE+CENTER_Y);
//		path.cubicTo(77.95f*SCALE+CENTER_X, 2.06f*SCALE+CENTER_Y,
//				81.85f*SCALE+CENTER_X, 2.78f*SCALE+CENTER_Y,
//				85.36f*SCALE+CENTER_X, 3.66f*SCALE+CENTER_Y);
//
//		path.moveTo(85.36f*SCALE+CENTER_X, 3.66f*SCALE+CENTER_Y);
//		path.cubicTo(104.88f*SCALE+CENTER_X, 8.54f*SCALE+CENTER_Y,
//				104.88f*SCALE+CENTER_X, 16.46f*SCALE+CENTER_Y,
//				85.36f*SCALE+CENTER_X, 21.34f*SCALE+CENTER_Y);
//
//		path.moveTo(85.36f*SCALE+CENTER_X, 21.34f*SCALE+CENTER_Y);
//		path.cubicTo(84.06f*SCALE+CENTER_X, 21.66f*SCALE+CENTER_Y,
//				82.72f*SCALE+CENTER_X, 21.96f*SCALE+CENTER_Y,
//				81.33f*SCALE+CENTER_X, 22.24f*SCALE+CENTER_Y);
//
//		//4
//		path.moveTo(81.33f*SCALE+CENTER_X, 22.24f*SCALE+CENTER_Y);
//		path.cubicTo(61.69f*SCALE+CENTER_X, 26.2f*SCALE+CENTER_Y,
//				32.88f*SCALE+CENTER_X, 25.9f*SCALE+CENTER_Y,
//				14.64f*SCALE+CENTER_X, 21.34f*SCALE+CENTER_Y);

		canvas.drawPath(path, paint);
	}

}
